﻿<Window x:Class="WindowChromeSample.SelectableChromeWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
    xmlns:local="clr-namespace:WindowChromeSample"
    Title="SelectableChromeWindow"
    Icon="app.ico"
    x:Name="ThisWindow"
    Width="300" Height="350">
  <!-- Copyright Microsoft Corporation. All Rights Reserved. -->
  <Window.CommandBindings>
    <CommandBinding Command="{x:Static shell:SystemCommands.CloseWindowCommand}"
                    Executed="_OnSystemCommandCloseWindow"/>
  </Window.CommandBindings>

  <Window.Resources>
    <local:CaptionButtonRectToMarginConverter x:Key="CaptionButtonMarginConverter"/>

    <Style x:Key="GlassStyle" TargetType="{x:Type local:SelectableChromeWindow}">
      <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
          <shell:WindowChrome GlassFrameThickness="-1" />
        </Setter.Value>
      </Setter>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type local:SelectableChromeWindow}">
            <Grid>
              <ContentPresenter
                  Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}" Content="{TemplateBinding Content}"/>
              <Button shell:WindowChrome.IsHitTestVisibleInChrome="True"
                  VerticalAlignment="Top" 
                  HorizontalAlignment="Left" 
                  Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}" 
                  Padding="8">
                <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}" Width="32" Height="32"/>
              </Button>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <Style x:Key="GradientStyle" TargetType="{x:Type local:SelectableChromeWindow}">
      <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
          <shell:WindowChrome
            ResizeBorderThickness="6"
            CaptionHeight="40"
            CornerRadius="6,0,6,20"
            GlassFrameThickness="0"/>
        </Setter.Value>
      </Setter>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type local:SelectableChromeWindow}">
            <Grid>
              <Border BorderThickness="6" BorderBrush="#3b5998">
                <Border.Background>
                  <LinearGradientBrush StartPoint="0,0" EndPoint="0,50" MappingMode="Absolute">
                    <GradientStop Offset="0" Color="#8b9dc3"/>
                    <GradientStop Offset="1" Color="#3b5998"/>
                  </LinearGradientBrush>
                </Border.Background>
                <ContentPresenter Margin="6,26,6,6" Content="{TemplateBinding Content}"/>
              </Border>
              <Button shell:WindowChrome.IsHitTestVisibleInChrome="True"
                  VerticalAlignment="Top" 
                  HorizontalAlignment="Left" 
                  Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}" 
                  Padding="10">
                <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}" Width="32" Height="32"/>
              </Button>

              <Button shell:WindowChrome.IsHitTestVisibleInChrome="True"
                  VerticalAlignment="Top" 
                  HorizontalAlignment="Right"
                  Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowCaptionButtonsLocation, Converter={StaticResource CaptionButtonMarginConverter}}"
                  Width="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowCaptionButtonsLocation.Width}"
                  Height="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowCaptionButtonsLocation.Height}"
                  Command="{x:Static shell:SystemCommands.CloseWindowCommand}"
                  CommandParameter="{Binding ElementName=ThisWindow}">
                <Bold shell:WindowChrome.IsHitTestVisibleInChrome="False">XXX</Bold>
              </Button>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </Window.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
      <RowDefinition Height="*"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Button Grid.Row="0" Margin="10" Click="_OnStandardChromeClicked">Standard Chrome</Button>
    <Button Grid.Row="1" Margin="10" IsEnabled="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=IsGlassEnabled}" Click="_OnGlassyChromeClicked">Glassy Chrome</Button>
    <Button Grid.Row="2" Margin="10" Click="_OnGradientChromeClicked">Gradient Chrome</Button>
  </Grid>
</Window>
